#include <iostream>
#include <fstream>
#include <d3dx9.h>
using namespace std;

ostream & operator<<(ostream &os, D3DXVECTOR3 &v) {
  os << "(" << v.x << "," << v.y << "," << v.z << ")";
  return os;
}

ostream & operator<<(ostream &os, D3DXVECTOR4 &V){
  os << "(" << V.x << "," << V.y << "," << V.z <<
    "," << V.w << ")";
  return os;
}

ostream & operator<<(ostream &os, D3DXMATRIX &m){
  for (int i = 0; i < 4; ++i){
    for (int j = 0; j < 4; ++j){
      os << m(i,j) << " ";
    }
    os << endl;
  }
  return os;
}
int main(int argc, char **argv) {
  D3DXVECTOR3 u(1.0f, 2.0f, 3.0f);
  D3DXMATRIX A(1.0f, .0f, .0f, .0f,
	      .0f, 2.0f, .0f, .0f,
	      .0f, .0f, 4.0f, .0f,
	      1.0f, 2.0f, 3.0f, 1.0f);
  D3DXMATRIX B;

  //matrix-matrix multiplication
  D3DXMATRIX C = A*B;
  D3DXMATRIX D, E, F;
  D3DXMatrixTranspose(&D, &A);

  D3DXMatrixInverse(&E, 0, &A);

  F = A * E;

  D3DXVECTOR4 P(2.0f, 2.0f, 2.0f, 1.0f);
  D3DXVECTOR4 Q;
  D3DXVec4Transform(&Q, &P, &A);

  /*cout << "A= " << endl << A << endl;
  cout << "B= " << endl << B << endl;
  cout << "C=A*B= " << endl << C << endl;
  cout << "D = transpose(A) = " << endl << D << endl;
  cout << "E = inverse(A) " << endl << E << endl;
  cout << "F = A * E = " << endl << F << endl;
  cout << "P = " << endl << P << endl;
  cout << "Q = P*A " << endl << Q << endl;*/

  IDirect3D9 *d3dObject = Direct3DCreate9(D3D_SDK_VERSION);
  ofstream outFile("modes.txt", fstream::out);
  D3DDISPLAYMODE mode;
  for (int i = 0; i < d3dObject->GetAdapterCount(); ++i) {
    UINT modeCnt = d3dObject->GetAdapterModeCount(i, D3DFMT_X8R8G8B8);
    outFile << "video card: " << i << endl;
    for (int j = 0; j < modeCnt; ++j) {
      d3dObject->EnumAdapterModes(i, D3DFMT_X8R8G8B8, j, &mode);
      outFile << "Width = " << mode.Width << "  ";
      outFile << "Height = " << mode.Height << "  ";
      outFile << "Format = " << mode.Format << "  ";
      outFile << "Refresh = " << mode.RefreshRate << endl;
    }
  }
  outFile.close();
  D3DXMATRIX scaleMaxtrix;
  D3DXMatrixScaling(&scaleMaxtrix, 10.0f, 10.0f, .0f);
  cout << "scale matrix is " << endl << scaleMaxtrix << endl;

  return 0;
  
  float x[3] = {-2.0f, 1.0f, -3.0f};
  D3DXVECTOR3 v(x);

  D3DXVECTOR3 a, b, c, d, e;
  a = u + v;
  b = u - v;
  c = u * 10;
  float length = D3DXVec3Length(&u);

  D3DXVec3Normalize(&d, &u);
  float s = D3DXVec3Dot(&u, &v);

  D3DXVec3Cross(&e, &u, &v);

  cout << "u	= " << u << endl;
  cout << "v	= " << v << endl;
  cout << "a	= " << a << endl;
  cout << "b	= " << b << endl;
  cout << "c	= " << c << endl;
  cout << "d	= " << d << endl;
  cout << "e	= " << e << endl;
  cout << "||u||	= " << length << endl;
  cout << "u dot v	= " << s << endl;
  
  return 0;
	


}
